package com.zhengxyou.jetpackdemo.daggerDemo;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.zhengxyou.jetpackdemo.R;
import com.zhengxyou.jetpackdemo.daggerDemo.bean.Cloth;
import com.zhengxyou.jetpackdemo.daggerDemo.bean.Clothes;
import com.zhengxyou.jetpackdemo.daggerDemo.bean.ClothsHandle;
import com.zhengxyou.jetpackdemo.daggerDemo.bean.Shoe;
import com.zhengxyou.jetpackdemo.daggerDemo.component.DaggerMainC;
import com.zhengxyou.jetpackdemo.daggerDemo.component.MainC;
import com.zhengxyou.jetpackdemo.daggerDemo.module.RedCloth;

import javax.inject.Inject;
import javax.inject.Named;

import androidx.appcompat.app.AppCompatActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * s@see https://www.jianshu.com/p/1d84ba23f4d2
 * https://dreamerhome.github.io/2016/07/07/dagger/?utm_source=tuicool
 */
public class DaggerActivity extends AppCompatActivity {
    @BindView(R.id.textView2)
    TextView textView2;
    @Inject
    @Named("red")
    Cloth cloth;
    @Inject
    @Named("blue")
    Cloth blueCloth;
    @Inject
    @RedCloth
    Cloth blackCloth;

    @Inject
    Clothes clothes;

    @Inject
    Shoe shoe;

    @Inject
    ClothsHandle clothsHandle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dagger);
        ButterKnife.bind(this);
        MainC component = DaggerMainC.builder().build();
        component.inject(this);
        Log.e("TAG", cloth.toString() + "," + blueCloth.toString());
        textView2.setText("这是一个" + cloth.toString() + "," + shoe.toString());
        textView2.append(",还有" + clothes.toString());
        textView2.append("\r\n");
        textView2.append(cloth.toString() + "," + blueCloth.toString());
        textView2.append("\r\n");
        textView2.append(",还有" + blackCloth.toString());
        textView2.append("\r\n");
        textView2.append("blueCloth=clothes中的cloth吗:" + (blueCloth == clothes.getCloth()));

        textView2.append("\r\n" + "clothsHandle:" + clothsHandle.hanlde(blueCloth) + "clothHandler地址:" + clothsHandle);
        Log.e("TAG", clothsHandle + "");

    }

    @OnClick(R.id.textView2)
    public void click() {
        Main4Activity.start(this);
    }

    public static void start(Context context) {
        Intent starter = new Intent(context, DaggerActivity.class);
        context.startActivity(starter);
    }
}
